using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI.WebControls;
using System.Xml;
using Butterfly.Library.Utilities;

namespace Butterfly.Library
{
    public class Definition
    {
        private const string CONFIG_FILENAME = "/Modules/CMS/CMS.config";

        public const string Portal_SiteName = "Portal.SiteName";
        public const string Portal_Home_Portal = "Portal.Home.Portal";
        public const string Portal_Home_Tab = "Portal.Home.Tab";
        public const string Portal_Search_Tab = "Portal.Search.Tab";
        public const string Portal_Content_Tab = "Portal.Content.Tab";
        public const string Portal_Zone_Tab = "Portal.Zone.Tab";
        public const string Portal_Zone_Active = "Portal.Zone.Active";
        public const string Portal_Product_Page = "Portal.Product.Page";
        public const string Portal_Default_Role = "Portal.Default_Role";
        public const string Portal_BusinessInfomation_TabChartAnalysis = " Portal.BusinessInfomation_TabChartAnalysis";
        public const string Portal_BusinessInfomationDetail_Tab = "Portal.BusinessInfomation_Detail_Tab";
        public const string Portal_BusinessInfomation_Tab = "Portal.BusinessInfomation_Tab";

        public const string Portal_Admin_Cookie = "Butterfly.Portal.Cookie_Admin_DMCS";
        public const string Portal_Cookie = "Butterfly.Portal.Cookie_DMCS";
        public const string Portal_Contact_Mail = "Portal.Contact.M.il";
        public const string Portal_Mail_Server = "Portal.Mail.Server";
        public const string Portal_Mail_User = "Portal.Mail.User";
        public const string Portal_Mail_Password = "Portal.Mail.Password";
        public const string Portal_CopyRight = "Portal.CopyRight";
        public const string Portal_Hit_Counter = "Portal.Hit.Counter";
        public const string Portal_Style = "Portal.Style";
        public const string CMS_Viewed_Cookie_Name = "CMS.Viewed_Cookie_Name";
        public const string Portal_Active = "Portal.Active";

        public static double CacheTime
        {
            get { return ConvertUtility.ToDouble(AppEnv.GetAppSetting("CacheExpire_Zone", CONFIG_FILENAME)); }
        }

        public static string UploadPath
        {
            get { return AppEnv.GetAppSetting("UploadPath", CONFIG_FILENAME); }
        }

        // Nam added

        public static string NameSqlProvider = "SqlDataProvider1";

        public static string StringIndent(int level)
        {
            string retVal = string.Empty;
            for (int i = 0; i < level; i++)
                retVal += ".....";
            return retVal;
        }

        public static void SelectItemFromList(ListControl list, string selectedValue)
        {
            list.SelectedIndex = -1;
            ListItem item = list.Items.FindByValue(selectedValue);
            if (item != null)
                item.Selected = true;
        }

        public static string GetValueStatus(string key, string configFileName)
        {
            XmlDocument xd = new XmlDocument();
            xd.Load(HttpContext.Current.Server.MapPath(configFileName));
            XmlNode node = xd.DocumentElement.SelectSingleNode(key);
            if (node != null) 
                return node.Attributes.GetNamedItem("value").Value;
            else 
                return null;
        }
    }
}
